<?php
/**
 * Created by PhpStorm.
 * User: yanghe
 * Date: 2016/4/26
 * Time: 14:56
 */
namespace MyClass\User;

use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Session;


class UserBase
{
    private  $user_id;

    public static function userAdd($data)
    {
        $res=DB::table("user")->insert($data);
        if($res)
        {
            return true;
        }
        else
        {
            return false;
        }
    }

    public static function login($data)
    {
        $inputData=DB::table("user")->where("user_nickname",$data["user_name"])
            ->pluck("user_password");
        if($inputData)
        {
            if($inputData[0] ==$data["user_password"])
            {
                return true;
            }
            else
            {
                return false;
            }

        }
        else
        {
            return false;
        }

    }
    public static function logout()
    {
        Session::flush();

        return true;
    }

    public function __construct($user_id)
    {
        $this->id=$user_id;
    }

    public function userUpdate($data)
    {
        $res=DB::table("user")->where("user_id","=",$this->id)->update($data);
        if($res)
        {
            return true;
        }
        else
        {
            return false;
        }
    }
}